<script setup lang="ts">
import SList from '@/components/common/list/SList.vue'
import { useList } from '@/composables/list-composable'
import type { ResultData } from '@/api/service'
import type { Page } from '@/type/User'
import { viewListApi } from '@/api/view'
import type { ViewVo } from '@/type/common/view-types'
import { useRouter } from 'vue-router'

const router = useRouter()

const viewId = 'ViewList'
const { tableData, pageQuery, statement, total, tableLoading, search } = useList(
  viewId,
  getData,
  () => {}
)

function getData() {
  tableLoading.value = true
  viewListApi(pageQuery).then((response: ResultData<Page<ViewVo[]>>) => {
    total.value = response.data.total
    tableData.value = response.data.modelList
    tableLoading.value = false
  })
}

const methods = {
  add: () => {
    router.push({ path: '/view/info' })
  },
  edit: (row: ViewVo) => {
    router.push({ path: '/view/info', query: { viewId: row.viewId } })
  }
}
</script>

<template>
  <s-list
    :statement="statement"
    :data="tableData"
    :methods="methods"
    :total="total"
    :table-loading="tableLoading"
    :page-size="pageQuery.pageSize"
    @search="search"
  >
  </s-list>
</template>

<style scoped></style>
